#!/bin/bash

# 恢复原始源码
cp -f lede-bak/original/feeds.conf.default lede
cp -f lede-bak/original/config/Config-images.in lede/config
cp -f lede-bak/original/package/network/services/uhttpd/Makefile lede/package/network/services/uhttpd
cp -f lede-bak/original/include/target.mk lede/include
cp -f lede-bak/original/target/linux/x86/Makefile lede/target/linux/x86
cp -f lede-bak/original/package/network/services/dropbear/files/dropbear.config lede/package/network/services/dropbear/files
cp -f lede-bak/original/package/lean/default-settings/Makefile lede/package/lean/default-settings
cp -f lede-bak/original/feeds/luci/collections/luci-ssl-nginx/Makefile lede/feeds/luci/collections/luci-ssl-nginx
cp -f lede-bak/original/package/lean/luci-app-cifsd/Makefile lede/package/lean/luci-app-cifsd
cp -f lede-bak/original/package/base-files/files/bin/config_generate lede/package/base-files/files/bin
cp -f lede-bak/original/package/network/services/dnsmasq/files/dhcp.conf lede/package/network/services/dnsmasq/files

# 恢复root用户名
mkdir -p lede-bak/user/package/base-files/files/etc && cp -f lede/package/base-files/files/etc/passwd lede-bak/user/package/base-files/files/etc
mkdir -p lede-bak/user/package/base-files/files/etc && cp -f lede/package/base-files/files/etc/shadow lede-bak/user/package/base-files/files/etc
mkdir -p lede-bak/user/package/system/rpcd/files && cp -f lede/package/system/rpcd/files/rpcd.config lede-bak/user/package/system/rpcd/files
mkdir -p lede-bak/user/feeds/luci/modules/luci-mod-admin-full/luasrc/controller/admin && cp -f lede/feeds/luci/modules/luci-mod-admin-full/luasrc/controller/admin/index.lua lede-bak/user/feeds/luci/modules/luci-mod-admin-full/luasrc/controller/admin
mkdir -p lede-bak/user/feeds/luci/modules/luci-base/luasrc/controller/admin && cp -f lede/feeds/luci/modules/luci-base/luasrc/controller/admin/servicectl.lua lede-bak/user/feeds/luci/modules/luci-base/luasrc/controller/admin
mkdir -p lede-bak/user/feeds/packages/net/nginx-util/files && cp -f lede/feeds/packages/net/nginx-util/files/uci.conf.template lede-bak/user/feeds/packages/net/nginx-util/files
mkdir -p lede-bak/user/package/lean/default-settings/files && cp -f lede/package/lean/default-settings/files/zzz-default-settings lede-bak/user/package/lean/default-settings/files

# 升级
cd lede
git pull && ./scripts/feeds update -a && ./scripts/feeds install -a && cd package/lean
rm -rf luci-theme-argon luci-app-argon-config luci-app-serverchan luci-app-adguardhome
git clone -b 18.06 https://github.com/jerrykuku/luci-theme-argon.git && git clone https://github.com/jerrykuku/luci-app-argon-config.git && git clone https://github.com/tty228/luci-app-serverchan.git && git clone https://github.com/rufengsuixing/luci-app-adguardhome.git && cd -